#include "..\include\DecorElement.hpp"
#include "assert.h"

DecorElement::DecorElement(SpritesManager* _spritesManager, DecorType type, int posXInit, int posYInit)
{
	spritesManager = _spritesManager;
	initialize(type, posXInit, posYInit);
}


DecorElement::~DecorElement(void)
{
}

void DecorElement::initialize(DecorType type, int posXInit, int posYInit){
	mType = type;

	x = posXInit;
	if (posYInit > 192){
		
		y = (192*2) - posYInit;
		screen = TOP;
	}
	else {
		y = 192 - posYInit;
		screen = BOTTOM;
	}

	if (x >= -32 && x < 300){
		displayed = true;
		displayDecorElement();
	}
	else {
		displayed = false;
	}
}

void DecorElement::displayDecorElement(){
	Sprite* image1 = new Sprite();
	if (screen == BOTTOM){
		if (mType == BARREL)
			image1->display(spritesManager, screen, x, y, OBJPRIORITY_3,spritesManager->BARREL, spritesManager->BARREL_PAL, DECOR_ELEMENT);
		else if (mType == PLATEFORM_BEG)
			image1->display(spritesManager, screen, x, y, OBJPRIORITY_3,spritesManager->PLATEFORM_BEG, spritesManager->PLATEFORM_PAL, DECOR_ELEMENT);
		else if (mType == PLATEFORM_MID)
			image1->display(spritesManager, screen, x, y, OBJPRIORITY_3,spritesManager->PLATEFORM_MID, spritesManager->PLATEFORM_PAL, DECOR_ELEMENT);
		else if (mType == PLATEFORM_END)
			image1->display(spritesManager, screen, x, y, OBJPRIORITY_3,spritesManager->PLATEFORM_END, spritesManager->PLATEFORM_PAL, DECOR_ELEMENT);
		else if (mType == ROCK)
			image1->display(spritesManager, screen, x, y, OBJPRIORITY_3,spritesManager->ROCK, spritesManager->ROCK_PAL, DECOR_ELEMENT);
	}
	else {
		if (mType == BARREL) assert(mType == BARREL && "No barrel in the sky !!");
			//image1->display(spritesManager, screen, x, y, OBJPRIORITY_3,spritesManager->BARREL_TOP, spritesManager->BARREL_PAL_TOP, DECOR_ELEMENT);
		else if (mType == PLATEFORM_BEG)
			image1->display(spritesManager, screen, x, y, OBJPRIORITY_3,spritesManager->PLATEFORM_BEG_TOP, spritesManager->PLATEFORM_PAL_TOP, DECOR_ELEMENT);
		else if (mType == PLATEFORM_MID)
			image1->display(spritesManager, screen, x, y, OBJPRIORITY_3,spritesManager->PLATEFORM_MID_TOP, spritesManager->PLATEFORM_PAL_TOP, DECOR_ELEMENT);
		else if (mType == PLATEFORM_END)
			image1->display(spritesManager, screen, x, y, OBJPRIORITY_3,spritesManager->PLATEFORM_END_TOP, spritesManager->PLATEFORM_PAL_TOP, DECOR_ELEMENT);
		else if (mType == ROCK) assert(mType == ROCK && "No rock in the sky !!");
			//image1->display(spritesManager, screen, x, y, OBJPRIORITY_3,spritesManager->ROCK_TOP, spritesManager->ROCK_PAL_TOP, DECOR_ELEMENT);
	}

	OAM_ID = image1->OAM_ID;
}
